//
//  LoginViewController.m
//  XDCommonApp
//
//  Created by XD-XY on 2/13/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "LoginViewController.h"
#import "XDTabBarViewController.h"
#import "UserInfo.h"
@interface LoginViewController ()

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self.leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    btn.backgroundColor = [UIColor grayColor];
    [btn setTitle:@"enter" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:btn];
}
-(void)btnclick
{
    [[UserInfo sharedUserInfo] setIsLogin:YES];
    NSInteger selectIndex = [XDTabBarViewController sharedXDTabBarViewController].presentIndex;
    NSInteger lastIndex = [XDTabBarViewController sharedXDTabBarViewController].beforeIndex;
    if ([[NEEDACCOUNTFORLOGIN objectAtIndex:selectIndex] isEqualToString:@"1"]){
        if ([UserInfo sharedUserInfo].isLogin){
            [[XDTabBarViewController sharedXDTabBarViewController] setSelectedIndex:selectIndex];
            [[XDTabBarViewController sharedXDTabBarViewController] confirmSelectTabBar:selectIndex];
        }else{
            [[XDTabBarViewController sharedXDTabBarViewController] setSelectedIndex:lastIndex];
            [[XDTabBarViewController sharedXDTabBarViewController] confirmSelectTabBar:lastIndex];
        }
    }
    [self back];
}

-(void)back
{
    NSInteger selectIndex = [XDTabBarViewController sharedXDTabBarViewController].presentIndex;
    if ([[NEEDACCOUNTFORLOGIN objectAtIndex:selectIndex] isEqualToString:@"1"]){
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
